package com.adjaisd.scarecrow.common.config.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AuthConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //addPathPatterns：哪些路径下的会被拦截
        //excludePathPatterns：哪些路径下不会被拦截
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/**/*.ico")
                .excludePathPatterns("/**/*.png", "/**/*.jpg", "/**/*.gif")
                .excludePathPatterns("/", "/**/*.html", "/**/*.js", "/**/*.css")
                .excludePathPatterns("/**/*.ttf", "/**/*.woff")

                .excludePathPatterns("/user/mail", "/user/register", "/user/verify")
                .excludePathPatterns("/login")
                .excludePathPatterns("/user/login", "/user/logout")

                .excludePathPatterns("/mqtt/auth")
                .excludePathPatterns("/device-gps/update")

                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/swagger-ui.html/**")
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v2/**")

                .excludePathPatterns("/user/nologin")
                .excludePathPatterns("/device/notoken")
                .excludePathPatterns("/device-status/action");
    }

}